package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdWeekCalendarImportVO;
import com.yunxi.otd.pojo.OtdWeekCalendarVO;
import com.yunxi.otd.service.OtdWeekCalendarDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 周生产日历 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-05-17
 */
@RestController
@RequestMapping("/admin/otd/weekCalendar")
@Api(tags = "OTD:WeekCalendar", description = "周生产日历接口")
public class OtdWeekCalendarController {

    private static final Logger logger = LoggerFactory.getLogger(OtdWeekCalendarController.class);

    //    @Reference(version = "${demo.service.version}",
//        application = "${dubbo.application.id}",
//        registry = "${dubbo.registry.address}",
//        url = "${dubbo.application.url}",
//        check = false,
//        timeout = 10000
//    )
    @Autowired
    OtdWeekCalendarDubboService otdWeekCalendarDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "pageNum", value = "页数", required = true),
        @ApiImplicitParam(name = "pageSize", value = "每页行数", required = true)
    })
    public ApiResult page(OtdWeekCalendarVO otdWeekCalendarVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil
            .ok(otdWeekCalendarDubboService.pageByVO(otdWeekCalendarVO, pageNum, pageSize));
    }

    @GetMapping("/load")
    @ApiOperation(value = "根据ID查询单条")
    @ApiImplicitParam(name = "calendarId", value = "周度工作日历ID", required = true)
    public ApiResult load(String calendarId) {
        return ResponseUtil.ok(otdWeekCalendarDubboService.getById(calendarId));
    }


    @GetMapping("/loadByWeek")
    @ApiOperation(value = "根据年月周查询单条")
    public ApiResult loadByWeek(String year, String week) {
        return ResponseUtil.ok(otdWeekCalendarDubboService.getByWeek(year, week));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public ApiResult add(@RequestBody OtdWeekCalendarVO otdWeekCalendarVO) {
        return otdWeekCalendarDubboService.addWeekCalendar(otdWeekCalendarVO);
    }

    @PostMapping("/modify")
    @ApiOperation(value = "修改")
    public ApiResult modify(@RequestBody OtdWeekCalendarVO otdWeekCalendarVO) {
        return otdWeekCalendarDubboService.modifyWeekCalendar(otdWeekCalendarVO);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "calendarIdList", value = "周度工作日历ID集合", required = true, allowMultiple = true, dataType = "String")
    public ApiResult remove(@RequestBody List<String> calendarIdList) {
        return otdWeekCalendarDubboService.removeCalendarByIds(calendarIdList);
    }

    @PostMapping("/import")
    @ApiOperation(value = "批量导入")
    public ApiResult importData(@RequestBody List<OtdWeekCalendarImportVO> calendarImportVOList) {
        return otdWeekCalendarDubboService.importData(calendarImportVOList);
    }
}
